const BaseIpcHandler = require('../BaseIpcHandler');

class CreateLocalModelHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> CreateLocalModelHandler params = ', params);
        // const { model_id, dataset_id, remote_id, env_name, train_cfg } = params;

        // 业务逻辑
        let result = null;
        try {
            const lastId = await this.app.db.models_local.insert(params);
            // console.log(`Local Model ${lastId} Created OK! params = `, params);
            result = { code: 0, msg: lastId };
        } catch (err) {
            console.error(`Error create local model: `, err);
            result = { code: -1, msg: err.message };
        }

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = CreateLocalModelHandler;
